home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc Source Code / Utilities / Interfaces / ODMath.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-22  |  3.1 KB  |  123 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        ODMath.h
  3.  
  4.     Contains:    Math routines (fixed-point and wide) for OpenDoc.
  5.  
  6.     Owned by:    Jens Alfke
  7.  
  8.     Copyright:    © 1994 - 1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     
  11.     In Progress:
  12.         
  13. */
  14.  
  15.  
  16. #ifndef _ODMATH_
  17. #define _ODMATH_
  18.  
  19.  
  20. #ifndef _ODTYPES_
  21. #include "ODTypes.h"
  22. #endif
  23.  
  24. #if _PLATFORM_MACINTOSH_
  25.     #ifndef __FIXMATH__
  26.     #include <FixMath.h>
  27.     #endif
  28.     #ifndef __TOOLUTILS__
  29.     #include <ToolUtils.h>
  30.     #endif
  31. #endif
  32.  
  33.  
  34. #if _PLATFORM_MACINTOSH_
  35. typedef wide ODWide;
  36. #else
  37. struct ODWide {                        // 64-bit integer
  38.     ODSLong hi;                            // High order longword comes first
  39.     ODULong lo;                            // Then low-order (which has no sign bit!)
  40. };
  41. #endif
  42.  
  43.  
  44. const ODFixed kODFixed1                = 0x00010000;
  45. const ODFixed kODFixedHalf            = 0x00008000;
  46. const ODFract kODFract1                = 0x40000000;
  47. const ODFixed kODFixedInfinity        = 0x7FFFFFFF;    // Fract as well
  48. const ODFixed kODFixedMinusInfinity    = 0x80000000;
  49.  
  50.  
  51. // Some of these fns are coded in assembly on 68k, so make calling conventions C:
  52. extern "C" {
  53.  
  54.  
  55. #define ODFixedRound(a)        ((ODSShort)((ODFixed)(a) + kODFixedHalf >> 16))
  56. #define ODIntToFixed(a)        ((ODFixed)(a) << 16)
  57. #define ODFixedToFract(a)    ((ODFract)(a) << 14)
  58. #define ODFractToFixed(a)    ((ODFixed)(a) + 8192L >> 14)
  59. #define ODFixedToFloat(a)    ((ODFixed)(a) / 65536.0)
  60. #define ODFloatToFixed(a)    ((ODFixed)((double_t)(a) * 65536.0))
  61.  
  62.  
  63. // These fixed-point math routines return infinity (see above) on overflow.
  64.  
  65. #if _PLATFORM_MACINTOSH_
  66.     #define ODFixedMultiply        FixMul
  67.     #define ODFixedDivide        FixDiv
  68.     #define ODFractMultiply        FracMul
  69.     #define ODFractDivide        FracDiv
  70.     
  71.     #ifdef __cplusplus
  72.     inline ODWide* ODWideMultiply( ODSLong a, ODSLong b, ODWide *result )
  73.     {
  74.         LongMul(a,b,(Int64Bit*)result);
  75.         return result;
  76.     }
  77.     #endif
  78. #else
  79. ODFixed    ODFixedMultiply( ODFixed a, ODFixed b );
  80. ODFixed    ODFixedDivide( ODFixed a, ODFixed b );
  81. ODFract    ODFractMultiply( ODFract a, ODFract b );
  82. ODFract    ODFractDivide( ODFract a, ODFract b );
  83. ODWide*    ODWideMultiply( ODSLong a, ODSLong b, ODWide *result );
  84. #endif
  85.  
  86. /*
  87. #if defined(_PLATFORM_MACINTOSH_) && (defined(powerc) || defined(__powerc))
  88.     #define ODWideCompare        WideCompare
  89.     #define ODWideNegate        WideNegate
  90.     #define ODWideShift            WideShift
  91.     #define ODWideAdd            WideAdd
  92.     #define ODWideSubtract        WideSubtract
  93.     #define ODWideMultiply        WideMultiply
  94.     #define ODWideDivide        WideDivide
  95.     #define ODWideSquareRoot    WideSquareRoot
  96. #else
  97. */
  98. ODSShort ODWideCompare( const ODWide*, const ODWide* );
  99. ODWide*    ODWideNegate( ODWide* );
  100. ODWide*    ODWideShift( ODWide*, ODSShort bits );    // Positive is toward MSB
  101. ODWide*    ODWideAdd( ODWide*, const ODWide* );
  102. ODWide*    ODWideSubtract( ODWide*, const ODWide* );
  103.  
  104. ODSLong    ODWideDivide( const ODWide *dividend,
  105.                             ODSLong divisor, ODSLong *remainder);
  106. ODULong ODWideSquareRoot( const ODWide *src );
  107. /*
  108. #endif
  109. */
  110. #define kODIgnoreRemainder  ((ODSLong*)-1L)    // Use as remainder in ODWideDivide
  111.  
  112. #define ODWideIsLong(w) ((w)->hi ==  0 && (long)(w)->lo >= 0 || \
  113.                           (w)->hi == -1 && (long)(w)->lo < 0)
  114.  
  115. ODFract    ODFractSinCos( ODFixed radians, ODFract *cos );    // returns sin
  116.  
  117. ODSShort    ODFirstBit( ODSLong );            // Returns index (0-32) of 1st bit
  118.  
  119.  
  120. }    // End of extern "C" {
  121.  
  122. #endif /*_ODMATH_*/
  123.